<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<jsp:include page="/common/adminLinks.jsp"/>
<div id="container-content" class="container-content">

    <form:form action="${pageContext.request.contextPath}/users/save" name="user" class="form-horizontal"
               modelAttribute="channelUser"
          method="post"  id="myForm">

        <div class="form-group" style="display: none">
            <label for="channelId" class="col-sm-2 control-label">渠道商id</label>
            <div class="col-sm-5">
                <form:input id="channelId" name="id" path="id" class="form-control"/>
            </div>
        </div>

        <div class="form-group ">
            <br>
            <br>
            <label for="username" class="col-sm-2 control-label" >用户名</label>
            <div class="col-sm-1 ">
                <form:input id="username" name="adminName" path="adminName" readonly="true" class="form-control" placeholder="必填且唯一" />
            </div>
        </div>
        <div class="form-group">
            <label for="nick" class="col-sm-2 control-label">昵称</label>
            <div class="col-sm-5">
                <form:input id="nick" name="adminNick" path="adminNick" class="form-control"/>
            </div>
        </div>

        <div class="form-group ">
            <label class="col-sm-2 control-label" for="roleGroup" >权限组</label>
            <div class="col-sm-5">
                <select id="roleGroup" name="groups"   class="form-control ">
                    <c:if test="${channelUser.groups[0].id==2}">
                        <option value="2" selected>管理员</option>
                    </c:if>
                    <c:if test="${channelUser.groups[0].id!=2}">
                        <option value="2" >管理员</option>
                    </c:if>

                    <c:if test="${channelUser.groups[0].id==7}">
                        <option value="7" selected>渠道商</option>
                    </c:if>
                    <c:if test="${channelUser.groups[0].id!=7}">
                        <option value="7">渠道商</option>
                    </c:if>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label" for="channelName">渠道名</label>
            <div class="col-sm-5">
                <form:select id="channelName" path="channelName"  name="channelName" class="form-control ">
                    <form:option value="ola">ola</form:option>
                    <form:option value="olb">olb</form:option>
                    <form:option value="olc">olc</form:option>
                    <form:option value="baidu">baidu</form:option>
                    <form:option value="defualt">defualt</form:option>
                </form:select>
            </div>
        </div>

        <div class="form-group" >
            <label  class="col-sm-2 control-label">重置密码</label>
             <a id="modify">重置</a>
        </div>
        <div class="form-group" id="channelPwd"  style="display:none;" >
            <label for="password" class="col-sm-2 control-label">设定密码</label>
            <div class="col-sm-5">
                <input id="password"  name="adminPassword" class="form-control" placeholder="不得少于6位"/>
            </div>
        </div>

        <div class="form-group">
            <label for="phone" class="col-sm-2 control-label">手机</label>
            <div class="col-sm-5">
                <form:input id="phone" name="telPhone" path="telPhone" class="form-control" placeholder="必填"/>
            </div>
        </div>

        <div class="form-group">
            <label for="email" class="col-sm-2 control-label">邮箱</label>
            <div class="col-sm-5">
                <form:input id="email" name="adminEmail" path="adminEmail" class="form-control" />
            </div>
        </div>

        <div class="form-group">
            <label for="qqNumber" class="col-sm-2 control-label">QQ</label>
            <div class="col-sm-5">
                <form:input id="qqNumber" name="qqNumber" path="qqNumber"  class="form-control" />
            </div>
        </div>

        <div class="form-group">
            <label for="relName" class="col-sm-2 control-label">真实姓名</label>
            <div class="col-sm-5">
                <form:input id="relName" name="relName" path="relName" class="form-control" />
            </div>
        </div>


        <div class="form-group">
            <label for="city" class="col-sm-2 control-label">所属城市</label>
            <div class="col-sm-5">
                <form:input id="city" name="city" path="city" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label for="status" class="col-sm-2 control-label" >状态</label>
            <div class="col-sm-5">
                <form:select id="status" name="status" path="status" class="form-control">
                    <form:option value="1">启用</form:option>
                    <form:option value="0">禁用</form:option>
                </form:select>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button id="save" type="button" class="btn btn-default">保存</button>
            </div>
        </div>

    </form:form>
</div>
<script src="/resources/common/js/jquery-1.11.1.min.js"></script>



<script>

    function modifyPwd() {
        $("#modify").click(function () {
                    if ($("#channelPwd").is(":visible") == false) {//点击修改的时候显示和隐藏切换
                        $("#channelPwd").show()
                    }
                    else {
                        $("#channelPwd").hide()
                    }
                }
        )
    }

    $(document).ready(function(){

        var success="${success}"
        if(success!=""){
            alert(success);

        }
        modifyPwd();
        $("#save").click(function(){
            var userName=$("#username").val();
            var password=$("#password").val();
            var phone=$("#phone").val();
            if (userName==""){
                alert("请填写用户名!")
                return;
            }
            if(password!="" && password.length<6){
                alert("密码长度不得小于6位")
                return;
            }else if(password==""){
                $("#password").val("${channelUser.adminPassword}")
            }
            if(phone==""){
                alert("请填写手机号")
                return;
            }
            if(userName!="${channelUser.adminName}"){
                var url="${pageContext.request.contextPath}/users/usernameUnique?userName="+userName;
                $.getJSON(url, function (data) {//data返回的数据
                    if (!data.success){
                        alert("改用户名已被注册过，请更换")
                    }else {
                       parent.a()
                        $("#myForm").submit()



                    }
                })
            }else {
                parent.a()
                $("#myForm").submit()

            }

        })
    })


</script>

